<template>
<div class="header">
    <div class="left">
        <i class="iconfont icon-logo"></i>
        <span>机器学习 • 管理控制台</span>
    </div>
    <div class="right">
        <avatar username="Jane Doe" :size="40"></avatar>
        <el-dropdown>
            <span class="el-dropdown-link">
          用户昵称<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>用户信息</el-dropdown-item>
                <el-dropdown-item @click.native="handleSignout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
    </div>
</div>
</template>

<script>
import Avatar from 'vue-avatar'
import { mapActions } from 'vuex'
export default {
    name: 'HeadNav',
    components: {
        Avatar
    },
    methods: {
        ...mapActions({
            logout: 'login/logout'
        }),
        handleSignout () {
            localStorage.setItem('token', '')
            this.$router.push('/login')
            // this.logout().then(res => {
            //     if (res) {
            //         localStorage.setItem('token', '')
            //         this.$router.push('/login')
            //     }
            // })
        }
    }
}
</script>

<style lang="less">
.header {
    height: 100%;

    .el-dropdown {
        margin-left: 15px;

        span {
            color: #ffffff;
        }
    }

    .left {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        height: 100%;
        float: left;

        i {
            font-size: 40px;
            color: #ffffff;
        }

        span {
            margin-left: 40px;
            color: #ffffff;
            font-size: 18px;
        }
    }

    .right {
        color: #ffffff;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        height: 100%;
        width: 200px;
        float: right;
    }
}
</style>
